/**
 *@Time    : 2021/11/12 00:53
 *@Author  : Shuai Jhou
 *@File    : httpServer
 *@Software: GoLand
 */

package main

import (
	"context"
	"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
	"go.zhoushuai.cn/go-programming-tour-book/grpc-pratice/services"
	"google.golang.org/grpc"
	"log"
	"net/http"
)

func main() {
	gwMutex := runtime.NewServeMux()
	//options := []grpc.DialOption{grpc.WithTransportCredentials(helper.GetServerCreds())}
	options := []grpc.DialOption{grpc.WithInsecure()}
	grpcEndPoint := "localhost:8081"
	ctx := context.Background()
	err := services.RegisterProdServiceHandlerFromEndpoint(ctx, gwMutex, grpcEndPoint, options)
	if err != nil {
		log.Fatal(err)
	}
	err = services.RegisterOrderServiceHandlerFromEndpoint(ctx, gwMutex, grpcEndPoint, options)
	if err != nil {
		log.Fatal(err)
	}
	httpServer := &http.Server{
		Addr:    ":8080",
		Handler: gwMutex,
	}
	httpServer.ListenAndServe()
}
